//////定义上传方法函数
var id="1";
function PreviewImage(imgFile) {
    var pattern = /(\.*.jpg$)|(\.*.png$)|(\.*.jpeg$)|(\.*.gif$)|(\.*.bmp$)/;
    if(!pattern.test(imgFile.value)) {
      alert("系统仅支持jpg/jpeg/png/gif/bmp格式的照片！");
      imgFile.focus();
    }else{
       //定义图片路径
       var path;
       //添加显示图片的HTML元素
       id += 1;
       $("#subjectimg").append("<div><div id='"+id+"'><img src='' /></div><a class='hide delete-btn'>删除</a></div>");
       //判断浏览器类型
       if(document.all){
       //兼容IE
        imgFile.select();
        path = document.selection.createRange().text;
        document.getElementById(id).innerHTML="";
        document.getElementById(id).style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src=\"" + path + "\")";//使用滤镜效果
       }else{
        //兼容其他浏览器
        path = URL.createObjectURL(imgFile.files[0]);
        document.getElementById(id).innerHTML = "<img src='"+path+"' width='300' height='220' />";
       }
       //重置表单
       resetForm(imgFile);
    }
}

//重置表单,允许用户连续添加相同的图片
function resetForm(imgFile){
  $(imgFile).parent()[0].reset();
}

//
// $('#subjectimg').on('click', '.delete-btn', function () {
//     var index = $(this).parent().index();
//     alert("========="+index)
//     $(this).parent().remove();
//     that.filesList.splice(index, 1);
//     console.log('我删除啦', index);
// });


//循环删除配图的
$("#subjectimg").off("mouseenter","div").on("mouseenter","div",function(){
    var index = $(this).parent().index();
    var that=this;
    var dom=$(that).children("a");
    dom.removeClass("hide");
    //为点击事件解绑，防止重复执行
    dom.off("click");
    dom.on("click",function(){
    	//删除当前图片
     	dom.parent().remove();
        var str="[";
        $("#subjectimg img" ).each(function(){
            str+="{'name':'"+$(this).attr("name")+"','imageUrl':'"+$(this).attr("src")+"'},";
        });
        str=str.substr(0,str.length-1);
        if(str!=""&&str!=null){
            str+="]"
        }
        $("#imageLists").val()
        $("#imageLists").val(str)
     });
}).off("mouseleave","img").on("mouseleave","img",function(){
    var that=this;
    $(that).children("a").addClass("hide");
})




//循环删除视频
$("#subjectvideo").off("mouseenter","div").on("mouseenter","div",function(){
    var index = $(this).parent().index();
    var that=this;
    var dom=$(that).children("a");
    dom.removeClass("hide");
    //为点击事件解绑，防止重复执行
    dom.off("click");
    dom.on("click",function(){
        //删除当前图片
        dom.parent().remove();
        var str="[";
        var strss="[";
        $("#subjectvideo video source" ).each(function(){
            strss+="{'name':'"+$(this).attr("name")+"','videoUrl':'"+$(this).attr("src")+"'},";
        });
        strss=strss.substr(0,strss.length-1);
        if(strss!=""&&strss!=null){
            strss+="]"
        }

        $("#videoLists").val()
        $("#videoLists").val(strss)
    });
}).off("mouseleave","img").on("mouseleave","img",function(){
    var that=this;
    $(that).children("a").addClass("hide");
})


//循环删除录音
$("#subjectrecord").off("mouseenter","div").on("mouseenter","div",function(){
    var index = $(this).parent().index();
    var that=this;
    var dom=$(that).children("a");
    dom.removeClass("hide");
    //为点击事件解绑，防止重复执行
    dom.off("click");
    dom.on("click",function(){
        //删除当前图片
        dom.parent().remove();
        var str="[";
        var strss="[";
        $("#subjectrecord video source" ).each(function(){
            strss+="{'name':'"+$(this).attr("name")+"','videoUrl':'"+$(this).attr("src")+"'},";
        });
        strss=strss.substr(0,strss.length-1);
        if(strss!=""&&strss!=null){
            strss+="]"
        }

        $("#recordingList").val()
        $("#recordingList").val(strss)
    });
}).off("mouseleave","img").on("mouseleave","img",function(){
    var that=this;
    $(that).children("a").addClass("hide");
})

